﻿@page
@inherits Acesoft.Web.UI.RazorPages.WebPage
@{
    ViewData["Title"] = "分级授权";
    Layout = "_shared/back";

    Ace.Layout().Fit(true).Items(layout =>
    {
        layout.Add().Border().Region(Region.north).Height(44).Controls(ctls =>
        {
            Ace.Search().Id("search").AppendTo(ctls).Height("38px").For("grid").Controls(query =>
            {
                Ace.TextBox().Name("keyword").AppendTo(query).Label("关键字：");
            })
            .Tools(tools =>
            {
                Ace.Button().AppendTo(tools).Text("添加").IconCls("fa fa-plus").Click("AX.gridAdd('#grid')");
                Ace.Button().AppendTo(tools).Text("删除").IconCls("fa fa-remove").Click("AX.gridDel('#grid')");
            });
        });
        layout.Add().Border(false).Region(Region.center).Controls(ctls =>
        {
            Ace.DataGrid().Id("grid").AppendTo(ctls).Pagination()
            .DataSource("rbac.scale").Ajax(ds => ds.HttpGet()).Columns(c =>
            {
                c.Add().Field("name").Title("下级名称").Width(5).Rowspan(2);
                c.Add().Field("ref_id").Title("关联Id").Width(5).Rowspan(2);
                c.Add().Field("remark").Title("说明").Width(10).Rowspan(2);
                c.Add().Title("设置管理员").Colspan(4);
                c.Add().Field("system").Title("系统").Format("bool").Rowspan(2);
                c.Add().Field("action").Title("操作").Format("button").Rowspan(2);
                c.AddRow();
                c.Add().Field("loginname").Title("登录名").Width(5);
                c.Add().Field("username").Title("姓名").Width(5);
                c.Add().Field("nickname").Title("昵称").Width(5);
                c.Add().Field("admin").Title("操作").Format("button").Width(5);
            });
        });
    }).Render();
}
<script>
    function event_grid_auth(cid, id) {
        var row = $('#grid').datagrid('getRow', id);
        AX.dialog('授权', '../user/auth?userid=' + row.admin_id, AX.ok);
    }
    function event_grid_add(cid, id) {
        AX.dialog('编辑', '../user/edit?type=1&scaleid=' + id, function () {
            AX.ok();
            $('#grid').datagrid('reload');
        });
    }
    function event_grid_adedit(cid, id) {
        var row = $('#grid').datagrid('getRow', id);
        AX.dialog('编辑', '../user/edit?id=' + row.admin_id, function () {
            AX.ok();
            $('#grid').datagrid('reload');
        });
    }
    function event_grid_addel(cid, id) {
        var row = $('#grid').datagrid('getRow', id);
        $.messager.confirm('提示', '确定要【移除】管理员？', function (r) {
            if (r) {
                AX.ajax({
                    url: AX.api({
                        api: 'auth/deluser',
                        q: 'id=' + row.admin_id
                    }),
                    type: 'delete',
                    cb: function () {
                        $.messager.info({ msg: '删除成功！' });
                        $('#grid').datagrid('reload');
                    }
                });
            }
        });
    }
</script>